package com.link.base.base.report.controller;

import com.link.base.base.report.model.DataMonitoringReport;
import com.link.base.base.report.service.DataMonitoringReportService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 大数据流程数据监控报表-
 *
 * @author 谢鑫
 * @date 2019/10/17 14:06
 */
@Controller
@RequestMapping("/link/dataMonitoringReport")
public class DataMonitoringReportController extends BasicController<DataMonitoringReport> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private DataMonitoringReportService dataMonitoringReportService;

    @Override
    public BasicService<DataMonitoringReport> getBasicService() throws Exception {
        return dataMonitoringReportService;
    }


    /**
     * 查询不同渠道的近七天的数据
     *
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryNewData", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Map<String, Object> queryNewData(@JsonParam DataMonitoringReport entity, HttpSession session, HttpServletRequest request,
                                             HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<DataMonitoringReport> record = dataMonitoringReportService.queryNewData();
            result.put("success", true);
            result.put("result", record);
            System.out.println(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 查询不同渠道的近七天的数据
     *
     * @param entity
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryDateData", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Map<String, Object> queryDateData(@JsonParam DataMonitoringReport entity, HttpSession session, HttpServletRequest request,
                                             HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<DataMonitoringReport> record = dataMonitoringReportService.queryDateData();
            result.put("success", true);
            result.put("result", record);
            System.out.println(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
